/**
* 模块的视图
* @author ES_ZETA
*  */
class WatcherPanel extends eui.Panel {
  protected watchers: eui.Watcher[];
  protected className: string;
  constructor() {
    super();
    this.watchers = [];
  }

  dispose() {
    this.onExit();
  }

  protected childrenCreated() {
    super.childrenCreated();
    this.onEnter();
  }

  public onEnter() {
    this.bindDatas();
    this.once(eui.UIEvent.REMOVED_FROM_STAGE, this.dispose, this);
  }

  public onExit() {
    this.unbindDatas();
    GameUtils.clearAllInterval(this);
    GameUtils.clearAllTimeout(this);
  }

  /** 关注数据*/
  protected bindDatas() {

  }

  protected bindData(host: any, chains: string[], handler: (value: any) => void, thisObject: any) {
    this.watchers.push(eui.Binding.bindHandler(host, chains, handler, thisObject));
  }

  /** 清除关注的数据 */
  protected unbindDatas() {
    this.watchers.map((value: eui.Watcher) => {
      value.unwatch();
    });
    this.watchers = [];
  }
}
